import { createRouter, createWebHistory } from "vue-router";
import { store } from '../components/userManagement/store.js'
export var route = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/home',
            children: [
                {
                    path: 'user',
                    name: 'testUser',
                    component: () => import('@/components/userTest/User.vue')
                },
                {
                    path: 'role',
                    name: 'testRole',
                    component: () => import('@/components/userTest/Role.vue')
                },
                {
                    path: 'question',
                    name: 'testQuestion',
                    component: () => import('@/components/userTest/Question.vue')
                },
            ]
        }
    ]
})

route.beforeEach((to, from, next) => {
    const isAuthenticated = store.state.isAuthenticated
    if (!isAuthenticated) {
        next({ name: 'Login' })
    } else {
        next()
    }
})